import base64
from pathlib import Path
from PIL import Image
from llms import moonshot_llm
def ocr_file_to_text_llm(file_path) -> str:
    """
    提取文件中的文本
    :param file_path:
    :return:
    """
    client = moonshot_llm()
    file_object = client.files.create(file=Path(file_path), purpose="file-extract")
    file_content = client.files.content(file_id=file_object.id).json()
    return file_content.get("content")

def get_b64_image_from_path(image_path):
  with open(image_path, "rb") as image_file:
    return base64.b64encode(image_file.read()).decode('utf-8')


def is_image(file_path):
    try:
        with Image.open(file_path) as img:
            img.verify()  # 验证文件是否是有效的图像
            return True
    except Exception as e:
        print(f"Error: {e}")
        return False